<template>
  <div>
    <cus-modal ref="modal" title="配置" width="650" @onOk="onOk">
      <Form ref="formValidate" :model="configForm" :label-width="80" inline>
        <FormItem v-for="(item, index) in configForm.configData" :key="item.id" :label="item.nameDescr" :prop="'configData.'+index+'.paramValue'"
          :rules="{required: true, message: `${item.nameDescr}必填！`, trigger: 'change,blur'}"
          >
          <Input clearable v-model="configForm.configData[index].paramValue" style="width: 250px"></Input>
          <div :class="item.valueDescr.length > 18 ? '' : 'descr'">
            {{ item.valueDescr }}

          </div>
        </FormItem>
        <Spin size="large" fix v-if="modelLoading"></Spin>
      </Form>
    </cus-modal>

  </div>
</template>

<script>
import { getSystemConfigList, editSystemConfigList } from "@/api/organ/organization";
export default {
  data() {
    return {
      configForm: {
        model: "",
        configData: [],
      },
      modelLoading: false,
     
    };
  },
  methods: {
    show(row) {
      console.log(row);
      this.getSystemConfigListApi(row);
      this.$refs["modal"].show = true;
    },
    onOk() {
      this.$refs['formValidate'].validate((valid) => {
        if (valid) {
          this.modelLoading = true;
          this.editSystemConfigListApi()
        }
      });
    },
    // 获取单位所有单位配置
    getSystemConfigListApi(row) {
      this.modelLoading = true
      return new Promise((resolve) => {
        getSystemConfigList({
          unitCode: row.unitCode,
        }).then((res) => {
          if (res.code == 1) {
            res.data.forEach(item => {
              if (item.valueItems) {
                item.valueList = JSON.parse(item.valueItems)
              }
            });
            this.configForm.configData = res.data;
          }
          this.modelLoading = false;
        });
      });
    },
    // 修改单位配置
    editSystemConfigListApi() {
      return new Promise((reslove) => {
        editSystemConfigList(
          {
            systemConfigEditList: this.configForm.configData
          }
        ).then((res) => {
          this.modelLoading = false;
          if (res.code == 1) {
            this.$Message.success('修改成功')
            this.$refs["modal"].show = false;
            this.$store.dispatch('getAreaListApi')
          }
        })
      })
    }
  },
};
</script>

<style scoped lang="scss">
.descr {
  float: right;
  margin-left: 10px;

}</style>
